// Generates a list of questions that can be used in a test.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chalmers.se.tda367.question;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Hanna
 */
public class TestQuestionListGenerator implements ITestQuestionListGenerator { // generates a list of questions to be used as a test

    private TestQuestionListGenerator() {  // constructor
    }

    public static ITestQuestionListGenerator newInstance() {  // TODO: comment
        return new TestQuestionListGenerator();
    }

    public List<IQuestion> getQuestionList(MathQuestionConFig mqc) { // creates the list of questions and returns it
        List<IQuestion> questionList = new LinkedList<IQuestion>();


        float sumOfParts = mqc.partAdd + mqc.partSub + mqc.partMul + mqc.partDiv; // add the different questionparts together
        int numberOfAddQuestions = (int) (mqc.numberOfQuestions * (mqc.partAdd / sumOfParts)); // calculates how many additionquestions there will be in the test and cast it to and int
        int numberOfSubQuestions = (int) (mqc.numberOfQuestions * (mqc.partSub / sumOfParts)); // with the values we've set there can't be a problem, but the programme should take in to
        int numberOfMulQuestions = (int) (mqc.numberOfQuestions * (mqc.partMul / sumOfParts)); // consideration that there could be other values
        int numberOfDivQuestions = (int) (mqc.numberOfQuestions * (mqc.partDiv / sumOfParts));

        for (int i = 0; i < numberOfAddQuestions; i++) {  // adds the correct number of additionquestions to the list, with the maxX and maxY set by the level
            questionList.add(new AdditionMathQuestion(mqc.maxXAddSub, mqc.maxYAddSub));
        }

        for (int i = 0; i < numberOfSubQuestions; i++) {
            questionList.add(new SubtractionMathQuestion(mqc.maxXAddSub, mqc.maxYAddSub));
        }

        for (int i = 0; i < numberOfMulQuestions; i++) {
            questionList.add(new MultiplicationMathQuestion(mqc.MaxXMulDiv, mqc.maxYMulDiv));
        }

        for (int i = 0; i < numberOfDivQuestions; i++) {
            questionList.add(new DivisionMathQuestion(mqc.MaxXMulDiv, mqc.maxYMulDiv));
        }

        Collections.shuffle(questionList); // shuffles teh list

        for (int i = 0; i < mqc.numberOfQuestions; i++) { // sets the number of the question
            questionList.get(i).questionNumber(i + 1);
        }

        return questionList;

        // TODO Make sure that the list can't contain less queastions than it's supposed to
    }

    public List<IQuestion> getQuestionList(LanguageQuestionConFig lqc) {
        return null;
    }
}
